package com.epoch.zuul.auth.service.impl;

import bean.response.ResponseBean;
import bean.response.ResultEnum;
import com.epoch.zuul.auth.dao.AuthDao;
import com.epoch.zuul.auth.role.Auth;
import com.epoch.zuul.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.ResultInfoUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 权限 AuthServiceImpl
 * @author Seven
 * @date 2021/12/3
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    private AuthDao authDao;

    @Override
    public ResponseBean getAuthByAuthId(Integer authId) {
        return ResultInfoUtil.buildSuccess(ResultEnum.OK, "根据Id查找权限成功", authDao.getAuthByAuthId(authId));
    }

    @Override
    public ResponseBean getAllAuths() {
        List<Auth> authList = authDao.getAllAuths();
        List<HashMap> result = new ArrayList<>(authList.size());
        for (int i = 0; i < authList.size(); i++){
            HashMap<String, String> authMap = new HashMap<>(3);
            Auth auth = authList.get(i);
            authMap.put("authName",auth.getAuthDescribe());
            authMap.put("authPath",auth.getAuthCode());
            String level = "三级";
            if (auth.getPid() == 0){
                level = "一级";
            }else if (auth.getIsMenu() == 1){
                level = "二级";
            }
            authMap.put("authLevel",level);
            result.add(authMap);
        }
        return ResultInfoUtil.buildSuccess(ResultEnum.OK, "获取权限列表成功", result);
    }

}
